// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/equipment/api/AssetChangeBorrowApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/equipment/model/ChangeBorrowListQueryReq'
import AddClass from '@api/equipment/model/InsertChangeBorrowReq'
import DelClass from '@api/equipment/model/ChangeDeleteReq'
import ChildClass from '@api/equipment/model/ChangeListDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const CHILDREN = [ChildClass, 'assetList', 1]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return !CORE.isEmpty(param.status)
  },
  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryChangeBorrowList', DTO)
    return [resp.comQuery.totalCount, resp.changeDtoList || [], resp.map || {}]
  },
  dealList([obj], { state: { MAP } }) {
    if (MAP.COUNT) MAP.COUNT = obj || {}
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增') {
    const DTO = CORE.grpcDTO(AddClass, one, CHILDREN)
    await CORE.grpc(TIP, CLIENT, 'insertChangeBorrow', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除') {
    const DTO = CORE.grpcDTO(DelClass, { changeIds: [id] })
    await CORE.grpc(TIP, CLIENT, 'deleteChangeReceive', DTO)
    return CORE.grpcOK(TIP)
  },
}
